package com.ryskoo.catering.productcate.repository;

import com.ryskoo.catering.constant.HCLCacheConstant;
import com.ryskoo.catering.productcate.domain.ProductCategoryPO;
import com.ryskoo.framework.core.bean.QueryMessageDTO;
import com.ryskoo.framework.core.repository.BasicRedisImpl;
import com.ryskoo.framework.core.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;
import java.util.List;

@Primary
@Repository
public class ProductCategoryRedisImpl extends BasicRedisImpl<ProductCategoryPO> implements IProductCategoryRepository {

    @Autowired
    private RedisUtil redisClient;
    @Autowired
    private IProductCategoryRepository productCategoryRepository;
    @PostConstruct
    public void init(){
        this.setRedisClient(redisClient);
        this.setDao(productCategoryRepository);
    }

    public ProductCategoryRedisImpl(){super(HCLCacheConstant.HCL_PRODUCTCATEGORY_KEY);}

    @Override
    public List<ProductCategoryPO> getListByVendorId(String vendorId) {
        return productCategoryRepository.getListByVendorId(vendorId);
    }

    @Override
    public List<String> getUuidsByNameAndVendorId(String name, String vendorId) {
        return productCategoryRepository.getUuidsByNameAndVendorId(name,vendorId);
    }

    @Override
    public List<String> getUuidsByNameAndVendorIdForUpdate(String name, String vendorId, String uuid) {
        return productCategoryRepository.getUuidsByNameAndVendorIdForUpdate(name,vendorId,uuid);
    }

    @Override
    public void changeStatus(List<String> uuids, boolean status) {
        productCategoryRepository.changeStatus(uuids,status);
    }

    @Override
    public int getMaxPosition(String vendorUuid) {
        return productCategoryRepository.getMaxPosition(vendorUuid);
    }

    @Override
    public List<ProductCategoryPO> queryFromES(QueryMessageDTO qm, boolean byPage) {
        return productCategoryRepository.queryFromES(qm, byPage);
    }

    @Override
    public int getCountFromES(QueryMessageDTO qm) {
        return productCategoryRepository.getCountFromES(qm);
    }

    /**
     * 同步至ES
     *
     * @param list
     */
    @Override
    public void syncToElastic(List<ProductCategoryPO> list) {
        productCategoryRepository.syncToElastic(list);
    }

    /**
     * 删除ES里商品分类信息
     *
     * @param idList
     */
    @Override
    public void deleteProductFromES(List<String> idList) {
        productCategoryRepository.deleteProductFromES(idList);
    }
}
